<template>
  <div>
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>待建项项目
          </p>
        </div>
        <div class="topright">
          <!--<el-button type="info" @click="$router.go(-1)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe606;</span>返回
          </el-button>-->
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="component-listHeader">
      <div class="search-header">
        <div class="left-title">
          <p class="left-text">
            <span class="iconfont">&#xe61e;</span>
            待建项项目
          </p>
          <div class="right">
            <!-- <button  @click="add">添加</button> -->
          </div>
        </div>
      </div>
    </div>

    <div class="table">
      <el-table ref="multipleTable" :data="info" tooltip-effect="dark" style="width:100%" border>
        <el-table-column label="时间" align="center" width="135">
          <template slot-scope="scope">
            {{scope.row.createDate | dateFilter}}
          </template>
        </el-table-column>
        <el-table-column label="项目编号" align="center" prop="proNo"></el-table-column>
        <el-table-column label="项目名称" align="center" prop="proName"></el-table-column>
        <el-table-column label="项目状态" align="center" prop="CheckFlowStep"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <a
              class="options"
              @click.prevent="$router.push({name:'approveDetail',params:{proId:scope.row.proId}})"
            >查看详情</a>
            <div>
              <el-button
                v-show="scope.row.CheckFlowStep == '项目部文员审核通过' &&ms_RoleName == 'ProjectManager'"
                @click="handleIdea(scope.row.proId)"
                type="text"
                size="small"
                class="red"
                style="color:#1abc9a;"
              >审批意见</el-button>
              <el-button
                v-show="scope.row.CheckFlowStep == '项目部经理初审通过' &&ms_RoleName == 'CenterClerk'"
                @click="handleIdea(scope.row.proId)"
                type="text"
                size="small"
                class="red"
                style="color:#1abc9a;"
              >审批意见</el-button>
              <el-button
                v-show="scope.row.CheckFlowStep == '管理部文员通过' &&ms_RoleName == 'CenterDeputy'"
                @click="handleIdea(scope.row.proId)"
                type="text"
                size="small"
                class="red"
                style="color:#1abc9a;"
              >审批意见</el-button>
              <el-button
                v-show="scope.row.CheckFlowStep == '管理部副总通过' &&ms_RoleName == 'CenterBOSS'"
                @click="handleIdea(scope.row.proId)"
                type="text"
                size="small"
                class="red"
                style="color:#1abc9a;"
              >审批意见</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 审批意见 -->
    <div class="component-model">
      <el-dialog title="审核意见" :visible.sync="ideaModel.show" width="600px">
        <div class="hadRadio">
          <el-form
            ref="form"
            :model="ideaModel"
            label-width="100px"
            style="width:300px;margin:0 auto;"
          >
            <el-form-item label="审核意见：">
              <el-radio-group v-model="ideaModel.idea" style="margin-left:-30px;">
                <el-radio label="true">同意</el-radio>
                <el-radio label="false">驳回</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="备注：" style="width:300px;">
              <el-input type="textarea" v-model="ideaModel.remark" style="margin-left:20px;"></el-input>
            </el-form-item>
          </el-form>
        </div>
        <span slot="footer" class="dialog-footer">
          <el-button @click="ideaModel.show = false">取消</el-button>
          <el-button @click="ideaCommit">确定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      info: [{}],
      ms_RoleName:localStorage.getItem('roleName'),
      //审核意见弹窗的值
      ideaModel: {
        show: false,
        proId: "",
        remark: "",
        idea: ""
      }
    };
  },
  created() {
    this.dataInit();
  },
  mounted() {},
  methods: {
    // 表格数据初始化
    dataInit() {
      let that = this,
        suCb = res => {
          console.log(res.data)
          that.info = that.deepClone(res.data.data)
        },
        erCb = res => {
          console.log(res);
        },
        req = {
          url: "/api/web/proProject/selectProByFlowManager",
          methods: "post",
          data: {flowStep:"111"},
          success: suCb,
          error: erCb
        };
      if (localStorage.getItem("roleName") == "ProjectManager") {
        req.data.flowStep = "111";
      } else if (localStorage.getItem("roleName") == "CenterClerk") {
        req.data.flowStep = "121";
      } else if (localStorage.getItem("roleName") == "CenterDeputy") {
        req.data.flowStep = "311";
      } else if (localStorage.getItem("roleName") == "CenterBOSS") {
        req.data.flowStep = "321";
      }
      console.log(req);
      that.$https(req);
    },
    // 审批意见
    handleIdea(id) {
      this.ideaModel.show = true;
      this.ideaModel.proId = id;
    },
    // 审批意见提交
    ideaCommit() {
      let role = localStorage.getItem("roleName"),
        num;
      // 根据缓存里面的权限和弹窗的单选框值 来判断传递给后台的状态码
      if (role == "ProjectClerk" && this.ideaModel.idea == "false") {
        num = "111";
      } else if (role == "ProjectManager" && this.ideaModel.idea == "true") {
        num = "121";
      } else if (role == "ProjectManager" && this.ideaModel.idea == "false") {
        num = "129";
      } else if (role == "CenterClerk" && this.ideaModel.idea == "true") {
        num = "311";
      } else if (role == "CenterClerk" && this.ideaModel.idea == "false") {
        num = "319";
      } else if (role == "CenterDeputy" && this.ideaModel.idea == "true") {
        num = "321";
      } else if (role == "CenterDeputy" && this.ideaModel.idea == "false") {
        num = "329";
      } else if (role == "CenterBOSS" && this.ideaModel.idea == "true") {
        num = "531";
      } else if (role == "CenterBOSS" && this.ideaModel.idea == "false") {
        num = "539";
      } else {
        num = "0";
      }
      let that = this,
        suCb = res => {
          console.log("审批意见结果", res);
          if (res.data.flag == 1) {
            that.$msg("提交成功！");
            that.ideaModel.show = false;
            that.dataInit();
          }
        },
        erCb = res => {
          that.$msg("提交失败，权限受限！");
        },
        req = {
          url: "/api/web/proProject/checkedProJect",
          methods: "post",
          data: {
            proId: that.ideaModel.proId,
            number: num,
            errorDesc: that.ideaModel.remark,
            updateUser: localStorage.getItem("ms_userId")
          },
          success: suCb,
          error: erCb
        };
      console.log(req.data);
      if (req.data.errorDesc == "" && that.ideaModel.idea == "false") {
        that.$msg("提交失败，驳回必须填写备注！");
      } else if (req.data.number == 0) {
        that.$msg("提交失败，您的角色没有权利提交！");
      } else {
        that.$https(req);
      }
    }
  },
  watch: {}
};
</script>
<style scoped>
.component-listHeader .search-header {
  width: 1100px;
  box-sizing: border-box;
  border: 1px solid rgba(228, 228, 228, 1);
  background-color: rgba(255, 255, 255, 1);
  margin: 20px auto 0;
  border-bottom: 0;
}

.component-listHeader .search-header .left-title {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background-color: rgba(243, 243, 243, 1);
  height: 45px;
  box-sizing: border-box;
}

.component-listHeader .search-header .left-title .left-text {
  width: 20%;
  color: #666;
  font-family: "微软雅黑";
  font-weight: 400;
  font-size: 12px;
  line-height: 45px;
  text-align: left;
  margin: 0 0 0 30px;
}

.component-listHeader .search-header .right {
  width: 70%;
  display: flex;
  justify-content: flex-end;
  margin-right: 10px;
}

.component-listHeader .search-header .right button {
  padding: 0 15px;
  height: 30px;
  width: 80px;
  margin: 6px 5px;
  line-height: 30px;
  font-size: 14px;
  color: #666;
  background-color: #fff;
  border: 1px solid #ccc;
}

.component-listHeader .search-header .right button:hover {
  background-color: #f3f3f3;
}

.component-listHeader .search-header .right .right-select-margin {
  margin-top: 6px;
  margin-right: 8px;
}
.table {
  width: 1100px;
  margin: 0 auto;
  margin-bottom: 20px;
}
a {
  cursor: pointer;
  color: #1abc9c;
}
</style>
